//
//  ViewController.m
//  XGCalendarDemo
//
//  Created by YaoZhaofeng on 15/6/15.
//  Copyright (c) 2015年 YaoZhaofeng. All rights reserved.
//

#import "ViewController.h"
#import "XGCalendar.h"

@interface ViewController ()<XGCalendarDelegate,XGCalendarDataSource>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    /*
     * Smooth scrolling in vertical direction
     * - to change to horizontal, change the scrollDirection to ScrollDirectionHorizontal
     * - to use paging scrolling, change pagingEnabled to YES
     * - to change the looks, please see documentation on Github
     * - the calendar works with any size
     */
    
    XGCalendar *calendar = [[XGCalendar alloc]initWithFrame:CGRectMake(0, [[UIApplication sharedApplication] statusBarFrame].size.height, [[UIApplication sharedApplication] statusBarFrame].size.width, [[UIScreen mainScreen] bounds].size.height - [[UIApplication sharedApplication] statusBarFrame].size.height)
                                            scrollDirection:ScrollDirectionHorizontal
                                              pagingEnabled:NO];
    
    calendar.delegate = self;
    calendar.dataSource = self;
    [self.view addSubview:calendar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -XGCalendarDataSource
- (NSInteger)XGCalendarTableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}
- (UITableViewCell *)XGCalendarTableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    [[cell textLabel] setTextAlignment:NSTextAlignmentCenter];
    [[cell textLabel] setTextColor:[UIColor colorWithWhite:0.2 alpha:0.8]];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    if ([indexPath row] == 1) {
        [[cell textLabel] setText:NSLocalizedString(@"No Events", @"A label for a table with no events.")];
    }
    else
    {
        [[cell textLabel] setText:@"haha"];
    }
    
    return cell;
}

- (int)XGCalendarView:(XGCalendar *)CalendarView scheduleCountForDate:(NSDate *)date{
    return rand()/100000;
}

#pragma mark -XGCalendarDelegate


- (void) XGCalendar:(XGCalendar *)calendar didSelectDate:(NSDate *)date
{
    [calendar setDisplayMode:XGCalendarViewModeWeek];
}

- (void)XGCalendarTableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (BOOL)XGCalendarTableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

- (void)XGCalendarTableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
    
}

- (NSString *)XGCalendarTableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
    return @"删除";
}

@end
